unit UnitNuevoMedico;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  UnitMedicos, sqldb;

type

  { TFormNuevoMedico }

  TFormNuevoMedico = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    nuevomedico_codigo : string;
    nuevomedico_nombre : string;
    nuevomedico_matricula : string;
  end; 

var
  FormNuevoMedico: TFormNuevoMedico;

implementation

{$R *.lfm}

{ TFormNuevoMedico }

procedure TFormNuevoMedico.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TFormNuevoMedico.Button1Click(Sender: TObject);
begin
  Edit1.Text := uppercase(Edit1.Text);

  SQLQuery1.SQL.Text := 'insert into medico(mdc_nombre, mdc_matricula) values(''' + Edit1.Text
    + ''', ''' + Edit2.Text + ''')';

  SQLQuery1.ExecSQL;

  SQLQuery1.SQL.Text := 'select mdc_cdg from medico where mdc_matricula = ' + Edit2.Text
    + ' and mdc_nombre = ''' + Edit1.Text + '''';

  SQLQuery1.Open;

  while not SQLQuery1.EOF do
  begin
    nuevomedico_codigo := SQLQuery1.Fields[0].AsString;
    SQLQuery1.Next;
  end;

  SQLQuery1.Close;

  nuevomedico_nombre := Edit1.Text;

  nuevomedico_matricula := Edit2.Text;

  ShowMessage('Alta Exitosa');

  Close();
end;

procedure TFormNuevoMedico.FormShow(Sender: TObject);
begin
  Edit1.Text := '';
  Edit2.Text := '';

  Edit1.SetFocus;
end;

end.

